/*
 * Created on 08.02.2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.opencube.omscube.test;

import org.opencube.oms.OMSData;
import org.opencube.oms.OMSElement;
import org.opencube.oms.meta.ComplexAttribute;
import org.opencube.oms.meta.OMSMetaData;

/**
 * @author cw
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Displayer{


	private void writeIndent( int indent, String s )
	{
		while( indent-- > 0 )
		{
			System.out.print( s );
		}
	}
	public void display( OMSElement element,OMSData data, int indent )
	{
		
		try {  
		String s ="   ";
		OMSMetaData metaData = data.getMetaData();
		writeIndent( indent, s );
		System.out.println( "<element id=\""+element.getId()+"\"  bookmark=\""+element.getBookmark()+"\" scheme=\"" + element.getSchemeName()+"\" displayName=\""+element.getDisplayName() + "\" modifyingDate=\""+element.getModifyingDate()+"\">" );
		ComplexAttribute[] atts = metaData.getScheme( element.getNamespacePath(), element.getSchemeName() ).getComplexAttributes();
		
		for( int i = 0; atts != null && i < atts.length; i++ )
		{
			OMSElement[] elements = element.getJoinedElements( atts[ i ].getName() );
			if( elements != null && elements.length > 0 )
			{
				writeIndent( indent + 1, s );
				System.out.println( "<cat("+atts[ i ].getType()+"):" + atts[ i ].getName() + ">" );
				for( int j = 0; elements != null && j < elements.length; j++ )
				{
					display( elements[ j ], data,indent + 2 );
				}
				writeIndent( indent + 1, s );
				System.out.println( "</cat("+atts[ i ].getType()+"):" + atts[ i ].getName() + ">" );
			}
		}
		writeIndent( indent, s );
		System.out.println( "</element>" );
		}catch (Exception e) { 
			e.printStackTrace();
		}
	}
}
